/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.nanosl.norg.ent;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Thilina
 */
@Entity
@Table(name = "person")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Person.findAll", query = "SELECT p FROM Person p"),
    @NamedQuery(name = "Person.findByNic", query = "SELECT p FROM Person p WHERE p.nic = :nic"),
    @NamedQuery(name = "Person.findByCode", query = "SELECT p FROM Person p WHERE p.code = :code"),
    @NamedQuery(name = "Person.findByNameInFull", query = "SELECT p FROM Person p WHERE p.nameInFull = :nameInFull"),
    @NamedQuery(name = "Person.findByFirstName", query = "SELECT p FROM Person p WHERE p.firstName = :firstName"),
    @NamedQuery(name = "Person.findByLastName", query = "SELECT p FROM Person p WHERE p.lastName = :lastName"),
    @NamedQuery(name = "Person.findByDateOfBirth", query = "SELECT p FROM Person p WHERE p.dateOfBirth = :dateOfBirth"),
    @NamedQuery(name = "Person.findByPassportNumber", query = "SELECT p FROM Person p WHERE p.passportNumber = :passportNumber"),
    @NamedQuery(name = "Person.findByBusiness", query = "SELECT p FROM Person p WHERE p.business = :business")})
public class Person implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "NIC")
    private String nic;
    @Column(name = "code")
    private Integer code;
    @Column(name = "name_in_full")
    private String nameInFull;
    @Column(name = "first_name")
    private String firstName;
    @Column(name = "last_name")
    private String lastName;
    @Column(name = "date_of_birth")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateOfBirth;
    @Column(name = "passport_number")
    private String passportNumber;
    @Column(name = "business")
    private String business;
    @JoinTable(name = "person_has_phone", joinColumns = {
        @JoinColumn(name = "person_NIC", referencedColumnName = "NIC")}, inverseJoinColumns = {
        @JoinColumn(name = "phone_phone_number", referencedColumnName = "phone_number")})
    @ManyToMany
    private Collection<Phone> phoneCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "person")
    private Collection<PersonHasPerson> personHasPersonCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "person1")
    private Collection<PersonHasPerson> personHasPersonCollection1;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "person")
    private Collection<PersonHasAddress> personHasAddressCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "person")
    private Collection<Employee> employeeCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "person")
    private Collection<User> userCollection;

    public Person() {
    }

    public Person(String nic) {
        this.nic = nic;
    }

    public String getNic() {
        return nic;
    }

    public void setNic(String nic) {
        this.nic = nic;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getNameInFull() {
        return nameInFull;
    }

    public void setNameInFull(String nameInFull) {
        this.nameInFull = nameInFull;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public Date getDateOfBirth() {
        return dateOfBirth;
    }

    public void setDateOfBirth(Date dateOfBirth) {
        this.dateOfBirth = dateOfBirth;
    }

    public String getPassportNumber() {
        return passportNumber;
    }

    public void setPassportNumber(String passportNumber) {
        this.passportNumber = passportNumber;
    }

    public String getBusiness() {
        return business;
    }

    public void setBusiness(String business) {
        this.business = business;
    }

    @XmlTransient
    public Collection<Phone> getPhoneCollection() {
        return phoneCollection;
    }

    public void setPhoneCollection(Collection<Phone> phoneCollection) {
        this.phoneCollection = phoneCollection;
    }

    @XmlTransient
    public Collection<PersonHasPerson> getPersonHasPersonCollection() {
        return personHasPersonCollection;
    }

    public void setPersonHasPersonCollection(Collection<PersonHasPerson> personHasPersonCollection) {
        this.personHasPersonCollection = personHasPersonCollection;
    }

    @XmlTransient
    public Collection<PersonHasPerson> getPersonHasPersonCollection1() {
        return personHasPersonCollection1;
    }

    public void setPersonHasPersonCollection1(Collection<PersonHasPerson> personHasPersonCollection1) {
        this.personHasPersonCollection1 = personHasPersonCollection1;
    }

    @XmlTransient
    public Collection<PersonHasAddress> getPersonHasAddressCollection() {
        return personHasAddressCollection;
    }

    public void setPersonHasAddressCollection(Collection<PersonHasAddress> personHasAddressCollection) {
        this.personHasAddressCollection = personHasAddressCollection;
    }

    @XmlTransient
    public Collection<Employee> getEmployeeCollection() {
        return employeeCollection;
    }

    public void setEmployeeCollection(Collection<Employee> employeeCollection) {
        this.employeeCollection = employeeCollection;
    }

    @XmlTransient
    public Collection<User> getUserCollection() {
        return userCollection;
    }

    public void setUserCollection(Collection<User> userCollection) {
        this.userCollection = userCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (nic != null ? nic.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Person)) {
            return false;
        }
        Person other = (Person) object;
        if ((this.nic == null && other.nic != null) || (this.nic != null && !this.nic.equals(other.nic))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.nanosl.norg.ent.Person[ nic=" + nic + " ]";
    }
    
}
